<template>
  <div>
    <van-nav-bar title="用户昵称" left-text="取消" right-text="完成" @click-left="$emit('colse')" @click-right="updateName"></van-nav-bar>
    <div class="box">
        <van-field
  v-model="message"
  rows="2"
  autosize
  type="textarea"
  maxlength="7"
  placeholder="请输入昵称"
  show-word-limit
/>
    </div>
  </div>
</template>

<script>
import { updateProfile } from '@/api/user'
export default {
  name: 'editName',
  data () {
    return {
      message: this.value
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  },
  components: {},

  computed: {},
  methods: {
    async updateName () {
      if (this.message.length <= 0) return this.$toast.fail('昵称不能为空')
      this.$toast.loading({
        message: '加载中',
        forbidClick: true,
        duration: 0 // 持续展示 toast
      })
      try {
        await updateProfile({
          name: this.message
        })
        console.log(this.message)
        this.$toast.success('修改成功')
        this.$emit('colse')
        this.$emit('input', this.message)
      } catch (err) {
        this.$toast.success('修改失败')
      }
    }
  }
}
</script>

<style lang='less' scoped>
.box{
    padding: 20px;
}
.van-popup {
  background: red;
}
</style>
